package jdk.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class ArrayListDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();

        list.add("name");
        list.add("sex");
        list.add("age");
        System.out.println(list);

        list.remove(1);
        System.out.println(list);

        list.isEmpty();
        list.add(1, null);
        System.out.println(list);

        list.toArray(new String[]{});
        list.indexOf(1);
        list.get(1);
        list.iterator();
        list.listIterator(2);


        Collection<String> collect = (Collection<String>)list;
        collect.iterator();
        collect.spliterator();


        /**
         * 并发访问注意事项
         * linkedList 和 ArrayList 一样，不是同步容器。所以需要外部做同步操作，或者直接用 Collections.synchronizedList 方法包一下，最好在创建时就包一下：
         * List list = Collections.synchronizedList(new LinkedList(...));
         */

        List list2 = Collections.synchronizedList(new ArrayList());

    }
}
